<template>
  <div>

    <SkyCardPanel title="HTML转义">
      <div slot="header-right">
        <SkyButton type="primary" @click="escape">转义</SkyButton>
      </div>
      <div slot="main">
        <div class="main">
          <div>
            <textarea v-model="into"></textarea>
          </div>
          <div>
            <textarea disabled v-model="out"></textarea>
          </div>
        </div>
      </div>
    </SkyCardPanel>

  </div>
</template>

<script>
export default {
  data () {
    return {
      into: '',
      out: '',
    }
  },
  methods: {
    escape () {
      this.out = this.HTMLEncode(this.into)
    },
    HTMLEncode (html) {
      var temp = document.createElement("div");
      (temp.textContent != null) ? (temp.textContent = html) : (temp.innerText = html);
      var output = temp.innerHTML;
      temp = null;
      return output;
    }
  }
}
</script>

<style lang="scss" scoped>
.main {
  display: flex;
  justify-content: space-between;
  & > div {
    width: 48%;
    height: 300px;
    textarea {
      width: 100%;
      height: 100%;
    }
  }
}
</style>